home *** CD-ROM | disk | FTP | other *** search
- Path: oasis.novia.net!not-for-mail
- From: tsyslo@oasis.novia.net (Tony Syslo)
- Newsgroups: comp.lang.c
- Subject: New C Programmer Has A Problem
- Date: 29 Jan 1996 06:26:10 GMT
- Organization: Novia Internetworking <> 28.8kbps dialup; 402/390-2NET
- Message-ID: <4ehpa3$6kl@nntp.novia.net>
- NNTP-Posting-Host: oasis.novia.net
- X-Newsreader: TIN [UNIX 1.3 BETA-950824-color PL0]
-
-
- START MESSAGE:
-
-
- I have a question on C... why isn't this program working?!
-
- Program START:
- /* File Open */
-
- #include <clib/dos_protos.h>
- #include <dos/dos.h>
- #include <stdio.h>
- #include <exec/types.h>
-
- void main();
-
- char *name;
- int age;
-
- void main()
-
- {
- struct FileHandle *file_handle;
- long bytes_written;
- long bytes_read;
-
- printf("Enter your name: ");
- scanf("%s",name);
- printf("\nEnter your age: "); scanf("%d",age);
-
-
- file_handle=(struct FileHandle *)
- Open("RAM:You.dat",MODE_NEWFILE);
- /* Have we opened the file successfully? */
- if(file_handle==NULL)
- {
- printf("Could not open the file!\n");
- Exit(0);
- }
- /* We have now opened a file, and are ready to start writing: */
- bytes_written=Write(file_handle,name,sizeof(name));
- bytes_written=bytes_written+Write(file_handle,age,sizeof(age));
-
- if(bytes_written!=sizeof(name)+sizeof(age))
- {
- printf("Could not save the list!\n");
- Close(file_handle);
- Exit(0);
- }
- else
- printf("Saved successfully!\n");
- printf("Memory cleared!\n");
- name="";
- age=0;
- printf("Loading!\n");
- Seek(file_handle,0,OFFSET_BEGINNING);
- bytes_read=Read(file_handle,name,sizeof(name));
- bytes_read=bytes_read+Read(file_handle,age,sizeof(age));
- if(bytes_written!=sizeof(name)+sizeof(age))
- {
- printf("Could not read the list!\n");
- Close(file_handle);
- Exit(0);
- }
- /* Print out the data: */
- printf("Hello, %s!\",name);
- printf("You are %d years old!\n",age);
- /* Close the file: */
- Close(file_handle);
- }
-
- Program END:
-
- Any help if MUCH appreciated...
-
- I am using the SAS/C 6.50 compiler...
-
- Also, is there any of you whom might have a routine to figure up random (or
- even psuedo-random) numbers?? Some algorithm, or such, as I need one BADLY!!
-
- MESSAGE END:
-